#!/usr/bin/python
"""
	input: 	a ctb-style parsed file
	output:	all rules in this file
"""
import tree
import rule
import sys

sys.stderr.write("usage: "+sys.argv[0]+" input-tree-file rule-file\n")

fi=file(sys.argv[1],'r')
lines=fi.readlines()
fi.close()
fo = file(sys.argv[2],'w')

rules = []
rules2 = []
rset = set()
for l in lines:
	pt = tree.Tree(l.strip())
	pt.parse()
	temprs = pt.generateRules(True,True)
	tmprs = pt.generateRules(False,False)
	rules.extend(temprs)
	fo.write(l)
	fo.write( 60*"="+"\n")
	for r in temprs:
		fo.write(r.toString()+"\n")
		#rset.add(r.toString())
	fo.write("\n")

	for r in tmprs:
		rules2.append(r.toString())
#sys.stderr.write("\n")
fo.close()

foo=file("rule-all",'w')
rset=set(rules2)
rules2=list(rset)
rules2.sort()
for r in rules2:
	foo.write(r+"\n")
foo.close()
